/*!
 * ======================================================
 * FeedBack Template For MUI (http://dev.dcloud.net.cn/mui)
 * =======================================================
 * @version:1.0.0
 * @author:cuihongbao@dcloud.io
 */
(function () {
    var index = 1;
    var size = null;
    var imageIndexIdNum = 0;
    var starIndex = 0;
    var feedback = {
        question: document.getElementById('question'),
        contact: document.getElementById('contact'),
        imageList: document.getElementById('image-list'),
        submitBtn: document.getElementById('submit')
    };
    var url = 'https://service.dcloud.net.cn/feedback';
    feedback.files = [];
    feedback.uploader = null;
    feedback.deviceInfo = null;
    mui.plusReady(function () {
        //设备信息，无需修改
        feedback.deviceInfo = {
            appid: plus.runtime.appid,
            imei: plus.device.imei, //设备标识
            images: feedback.files, //图片文件
            p: mui.os.android ? 'a' : 'i', //平台类型，i表示iOS平台，a表示Android平台。
            md: plus.device.model, //设备型号
            app_version: plus.runtime.version,
            plus_version: plus.runtime.innerVersion, //基座版本号
            os: mui.os.version,
            net: '' + plus.networkinfo.getCurrentType()
        }
    });
    /**
     *提交成功之后，恢复表单项
     */
    feedback.clearForm = function () {
        feedback.question.value = '';
        feedback.contact.value = '';
        feedback.imageList.innerHTML = '';
        feedback.newPlaceholder();
        feedback.files = [];
        index = 0;
        size = 0;
        imageIndexIdNum = 0;
        starIndex = 0;
        //清除所有星标
        mui('.icons i').each(function (index, element) {
            if (element.classList.contains('mui-icon-star-filled')) {
                element.classList.add('mui-icon-star')
                element.classList.remove('mui-icon-star-filled')
            }
        })
    };

    feedback.addFile = function (path) {
        feedback.files.push({name: "images" + index, path: path, id: "img-" + index});
        index++;
    };


    //应用评分
    mui('.icons').on('tap', 'i', function () {
        var index = parseInt(this.getAttribute("data-index"));
        var parent = this.parentNode;
        var children = parent.children;
        if (this.classList.contains("mui-icon-star")) {
            for (var i = 0; i < index; i++) {
                children[i].classList.remove('mui-icon-star');
                children[i].classList.add('mui-icon-star-filled');
            }
        } else {
            for (var i = index; i < 5; i++) {
                children[i].classList.add('mui-icon-star')
                children[i].classList.remove('mui-icon-star-filled')
            }
        }
        starIndex = index;
    });
    //选择快捷输入
    mui('.mui-popover').on('tap', 'li', function (e) {
        document.getElementById("question").value = document.getElementById("question").value + this.children[0].innerHTML;
        mui('.mui-popover').popover('toggle')
    })
})();
